
[dbo].[asi_NextSequenceValueTest]
CREATE proc [dbo].[asi_NextSequenceValueTest]
@sequenceName nvarchar(30),
@userKey uniqueidentifier,
@systemEntityKey uniqueidentifier = '00000000-0000-0000-0000-000000000000',
@increment int = 1,
@startValue int = 0 as
declare @lastValue int
set nocount on
exec asi_NextSequenceValueSub @sequenceName, @userKey, @systemEntityKey, @increment, @startValue, @lastValue output
if exists (select 1 from SystemConfig where ParameterName = 'EnableCounterFiltering' and ParameterValue = 'True')
begin
declare @checkValue int
declare @checkValueStr varchar(11)
set @checkValue = @lastValue - (@increment - 1)
while @checkValue <= @lastValue
begin
set @checkValueStr = convert (varchar(11), @checkValue)
while charindex('666', @checkValueStr) > 0
begin
exec asi_NextSequenceValueSub @sequenceName, @userKey, @systemEntityKey, 1, @startValue, @lastValue output
set @checkValue = @checkValue + 1
set @checkValueStr = convert (varchar(11), @checkValue)
end
set @checkValue = @checkValue + 1
end
end
set nocount off
select @lastValue CurrentValue
GO